<?php

namespace app\backend\controller;

use app\backend\service\MemberService;
use app\backend\service\SpreadService;

class Spread extends Backend
{
    public function index(SpreadService $service)
    {
        if ($this->request->isAjax()) {
            return $this->success($service->lists($this->request->param()));
        }
        return $this->fetch('', $service->labelData());
    }

    /**
     * 用户列表
     * @param MemberService $service
     * @return \think\response\Json
     * @throws \think\db\exception\DbException
     */
    public function member(MemberService $service)
    {
        return $this->success($service->lists($this->request->param()));
    }

    /**
     * 添加推广项目
     * @param SpreadService $service
     * @return string|\think\response\Json
     * @throws \app\common\RootException
     */
    public function add(SpreadService $service)
    {
        if ($this->request->isAjax()) {
            return $this->success($service->add($this->request->param()));
        }
        return $this->fetch('', $service->labelData());
    }

    /**
     * 修改推广项目
     * @param SpreadService $service
     * @return string|\think\response\Json
     * @throws \app\common\RootException
     */
    public function edit(SpreadService $service)
    {
        $params = $this->request->param();
        if ($this->request->isAjax()) {
            return $this->success($service->edit($params));
        }
        $fetchData = $service->labelData();
        $fetchData['info'] = $service->info($params['id']);
        return $this->fetch('', $fetchData);
    }

    /**
     * 推广详情
     * @param SpreadService $service
     * @return string
     */
    public function detail(SpreadService $service)
    {
        $fetchData = $service->labelData();
        $fetchData['info'] = $service->info($this->request->param('id'));
        return $this->fetch('', $fetchData);
    }
}